package com.engine.cn.mq;

import jakarta.annotation.Resource;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消费者配置
 */
@Configuration
public class RabbitConsumerConfig {
    @Resource
    private ConnectionFactory connectionFactory;

    @Bean
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);

        // 设置手动ACK，Acknowledge是承认认可的意思
        factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);

        // 设置消费者并发数量
        factory.setConcurrentConsumers(3);
        factory.setMaxConcurrentConsumers(10);

        // 设置消息预取数量
        factory.setPrefetchCount(50);
        return factory;
    }
}
